package question5.com.qee.jdbc;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * @ProjectName: learning
 * @Package: question5.com.qee.jdbc
 * @ClassName: MapUtils
 * @Description:
 * @Date: 2021/10/21 9:50 下午
 * @Version: 1.0
 */
public class MapUtils {

    public static <T> Map<String, Object> toMap(Class<?> clzzz, T obj) {
        Map<String, Object> result = new HashMap<>();
        Field[] declaredFields = clzzz.getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            try {
                result.put(field.getName(), field.get(obj));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return result;
    }
}
